import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import VueSetupExtend from 'vite-plugin-vue-setup-extend'
import postcssPxToViewport from 'postcss-px-to-viewport'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    VueSetupExtend(),
    AutoImport({
      // 后续vue/vue-router/pinia的API都不需要再单独import到setup里面了
      imports: ['vue', 'vue-router', 'pinia'],
      dts: false
    })
  ],
  resolve: {
    // 路径别名
    alias: {
      // 设置路径
      '~': path.resolve(__dirname, './'),
      '@': path.resolve(__dirname, './src')
    }
  },
  server: {
    port: 80,
    host: true,
    open: true,
    hmr: true,
    proxy: {
      '/api': {
        target: 'http://172.16.50.179:8083/', //测试环境
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },
  css: {
    postcss: {
      plugins: [
        // 布局适配
        postcssPxToViewport({
          viewportWidth: 1920
        })
      ]
    }
  }
})
